#include "VS2DTexSampler.h"
#include "VSShaderStringFactory.h"
#include "VSGraphicInclude.h"
using namespace VSEngine2;
unsigned int VS2DTexSampler::ms_uiIputNodeNum = 0;
unsigned int VS2DTexSampler::ms_uiOutputNodeNum = 0;
IMPLEMENT_RTTI(VS2DTexSampler,VSTexSampler)
BEGIN_ADD_PROPERTY(VS2DTexSampler,VSTexSampler)
END_ADD_PROPERTY
IMPLEMENT_INITIAL_BEGIN(VS2DTexSampler)
IMPLEMENT_INITIAL_END

VS2DTexSampler::VS2DTexSampler(const VSUsedName & ShowName,VSMaterial * pMaterial)
				:VSTexSampler(ShowName,pMaterial)
{
	
	

	VSString InputID = IntToString(ms_uiIputNodeNum);
	VSString InputName = _T("Tex2DSamplerInput") + InputID;
	VSInputNode * pInputNode = NULL;
	pInputNode = VS_NEW VSInputNode(VSPutNode::VT_2,InputName,this);
	VSMAC_ASSERT(pInputNode);
	m_pInput.AddElement(pInputNode);
	ms_uiIputNodeNum++;

	
	VSString OutputID = IntToString(ms_uiOutputNodeNum);
	VSString OutputName = _T("Tex2DSamplerOutput") + OutputID;
	VSOutputNode * pOutputNode = NULL;
	pOutputNode = VS_NEW VSOutputNode(VSPutNode::VT_4,OutputName,this);
	VSMAC_ASSERT(pOutputNode);
	m_pOutput.AddElement(pOutputNode);
	ms_uiOutputNodeNum++;


}
VS2DTexSampler::VS2DTexSampler()
{

}
VS2DTexSampler::~VS2DTexSampler()
{

}
bool VS2DTexSampler::GetFuntionString(VSString &OutString)const
{
	if(VSRenderer::ms_pRenderer)
		OutString += VSRenderer::ms_pRenderer->Tex2D(this);

	if (m_uiVESRGB)
	{
		VSString NodeString = VSRenderer::ms_pRenderer->GetValueElement(GetOutputNode(VS2DTexSampler::OUT_COLOR),m_uiVESRGB);

		OutString += NodeString + _T(" = ");
		VSRenderer::ms_pRenderer->GreaterZeroPow(NodeString,2.2f,OutString);
		OutString += _T(";\n");
	}

	if (m_uiVEDecode)
	{
		VSString NodeString = VSRenderer::ms_pRenderer->GetValueElement(GetOutputNode(VS2DTexSampler::OUT_COLOR),m_uiVEDecode);

		OutString += NodeString + _T(" = ");
		VSRenderer::ms_pRenderer->DecodeNormal1(NodeString,OutString);
		OutString += _T(";\n");
	}
	
	
	
	return 1;
}
void VS2DTexSampler::SetTexture(VSTexAllStateR * pTexAllState)
{
	if(!pTexAllState)
		return;
	if(pTexAllState->GetResource()->m_pTex->GetTexType() != VSTexture::TT_2D)
		return ;
	m_pTexAllState = pTexAllState;
}

